/**
 * 
 */
package de.homer.adapter.domain;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * @author André Stannek
 * 
 */
@Entity
@Table(name = "pluginConfigurations")
public class PluginConfiguration {

	/**
	 * 
	 */
	@Id
	@Column(name = "id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	/**
	 * 
	 */
	@ElementCollection
	private Map<String, String> configuration;

	/**
	 * 
	 */
	public PluginConfiguration() {
		super();
		configuration = new HashMap<>();
	}

	/**
	 * @param propertyNames
	 *            the names of initial properties
	 */
	public PluginConfiguration(final String... propertyNames) {
		this();
		for (String string : propertyNames) {
			addAttribute(string);
		}
	}

	/**
	 * Adds an attribute with an empty String as value.
	 * 
	 * @param name
	 *            the name of the attribute to add
	 */
	public final void addAttribute(final String name) {
		getConfiguration().put(name, "");
	}

	/**
	 * @param name
	 *            the name of the attribute
	 * @return the value of the attribute
	 */
	public final String getAttribute(final String name) {
		return getConfiguration().get(name);
	}

	/**
	 * @param name
	 *            the name of the attribute
	 * @param value
	 *            the value of the attribute
	 */
	public final void setAttribute(final String name, final String value) {
		getConfiguration().put(name, value);
	}

	/**
	 * @return the configuration
	 */
	public final Map<String, String> getConfiguration() {
		return configuration;
	}

	/**
	 * @param configuration
	 *            the configuration to set
	 */
	public final void setConfiguration(final Map<String, String> configuration) {
		this.configuration = configuration;
	}
}
